package org.example.contract.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import org.example.contract.domain.Contract;
import org.example.contract.mapper.ContractMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.example.contract.mapper.ContractCheckMapper;
import org.example.contract.domain.ContractCheck;
import org.example.contract.service.IContractCheckService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 合同审核Service业务层处理
 *
 * @author 小孟微信：xiaomengcode
 * @date 2024-05-03
 */
@Service
public class ContractCheckServiceImpl implements IContractCheckService
{
    @Autowired
    private ContractCheckMapper contractCheckMapper;
    @Autowired
    private ContractMapper contractMapper;



    /**
     * 查询合同审核
     *
     * @param contractCheckId 合同审核主键
     * @return 合同审核
     */
    @Override
    public ContractCheck selectContractCheckByContractCheckId(Long contractCheckId)
    {
        return contractCheckMapper.selectContractCheckByContractCheckId(contractCheckId);
    }

    /**
     * 查询合同审核列表
     *
     * @param contractCheck 合同审核
     * @return 合同审核
     */
    @Override
    @DataScope(deptAlias = "d",userAlias = "u")
    public List<ContractCheck> selectContractCheckList(ContractCheck contractCheck)
    {
        return contractCheckMapper.selectContractCheckList(contractCheck);
    }

    /**
     * 新增合同审核
     *
     * @param contractCheck 合同审核
     * @return 结果
     */
    @Override
    @Transactional
    public int insertContractCheck(ContractCheck contractCheck)
    {
        //更新合同状态
        Contract contract =new Contract();
        contract.setContractId(Long.parseLong(contractCheck.getContractId()));
        contract.setStatus(contractCheck.getStatus());
        contractMapper.updateContract(contract);

        //记录审核
        contractCheck.setCreateBy(ShiroUtils.getUserId()+"");
        contractCheck.setCreateTime(DateUtils.getNowDate());
        return contractCheckMapper.insertContractCheck(contractCheck);
    }

    /**
     * 修改合同审核
     *
     * @param contractCheck 合同审核
     * @return 结果
     */
    @Override
    public int updateContractCheck(ContractCheck contractCheck)
    {
        return contractCheckMapper.updateContractCheck(contractCheck);
    }

    /**
     * 批量删除合同审核
     *
     * @param contractCheckIds 需要删除的合同审核主键
     * @return 结果
     */
    @Override
    public int deleteContractCheckByContractCheckIds(String contractCheckIds)
    {
        return contractCheckMapper.deleteContractCheckByContractCheckIds(Convert.toStrArray(contractCheckIds));
    }

    /**
     * 删除合同审核信息
     *
     * @param contractCheckId 合同审核主键
     * @return 结果
     */
    @Override
    public int deleteContractCheckByContractCheckId(Long contractCheckId)
    {
        return contractCheckMapper.deleteContractCheckByContractCheckId(contractCheckId);
    }
}
